﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>云瑞家庭农场</title>
    <link rel="shortcut icon" href="~/Content/assets/i/miemie_favicon.ico" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="~/Content/layui/css/layui.css">
    <script src="~/Content/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/Scripts/jquery-3.3.1.js"></script>
    <script type="text/javascript">
        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;
            //日期
            laydate.render({
                elem: '#date'
            });
            laydate.render({
                elem: '#date1'
            });
            //创建一个编辑器
            var editIndex = layedit.build('LAY_demo_editor');
            $(document).ready(function () {
                $("#login").click(function () {
                    var UserName = $('#username').val();
                    var PassWord = $('#password').val();
                    form.verify({
                        username: function (value) {
                            if (value.length < 1) {
                                return '请输入用户名';
                            }
                        }
                        , pass: function (value) {
                            if (value.length < 1) {
                                return '请输入密码';
                            }
                        }
                    });
                    if (UserName == "" || PassWord == "") {
                        return;
                    }
                    $.ajax({
                        url: "/YunRuiFarmAPI/LoginAPI", //请求的URL
                        cache: true, //不从缓存中取数据
                        data: {
                            "UserName": UserName,
                            "PassWord": PassWord
                        }, //发送的参数
                        type: 'post', //请求类型
                        dataType: 'json', //返回类型是JSON
                        timeout: 20000, //超时
                    })
                        .done(function (result) {
                            if (result.IsSuccess) {
                                cookie("token", result.Message , { expires: 1 });
                                window.location.href = "/YunRuiFarm/Index";
                            } else {
                                layer.msg(result.Message);
                            }
                        });
                });
                $("#register").click(function () {
                    window.location.href = "/YunRuiFarm/Register";
                });
            });
            function cookie(key, value, options) {
                options = options || {};
                var cookie = encodeURIComponent(key) + "=" + value;
                if ((typeof options.expires) !== "undefined") {  
                    if (typeof options.expires === "number") { 
                        var days = options.expires,
                            t = options.expires = new Date();
                        t.setDate(t.getDate() + days);
                    }
                    cookie += ";expires=" + options.expires.toUTCString();
                }
                if (typeof options.path !== "undefined")
                    cookie += ";path=" + options.path;
                if (typeof options.domain !== "undefined")
                    cookie += ";domain=" + options.domain;
                if (options.secure)
                    cookie += ";secure";
                document.cookie = cookie;
            }  
        });

    </script>
    <style>
        body {
            text-align: left;
            background-image: url('../../Content/image/login_regestion_background.png');
            background-repeat: no-repeat;
            background-position: 0% 0%;
            background-size: cover;
            background-color: #22C3AA;
            font-size: 18px
        }
        #divtitle {
            margin: 0 auto;
            margin-top: 5%;
            margin-bottom: 5%;
            background-color: rgba(255,255,255,0.5)
        }
        #divcss1 {
            margin: 0 auto;
            border: 1px solid #c0c0c0;
            width: 50%;
            height:80%;
            background-color: rgba(255,255,255,0.5)
        }

        #divcss2 {
            margin-top: 10px;
        }

        #divcss3 {
            margin-top: 20px;
            margin-bottom: 20px;
            margin-left: 10%;
        }
    </style>
</head>
<body>
    <div id="divtitle">
        <fieldset class="layui-elem-field layui-field-title" >
            <legend >云瑞家庭农场管理系统登录页面</legend>
        </fieldset>
    </div>
    <div id="divcss1">
        <div id="divcss2">
            <div id="divcss3">
                <form class="layui-form" action="">

                    <div class="layui-form-item" style="margin-left: 10%;">
                        <div class="layui-form-item">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="username" lay-verify="username" placeholder="请输入用户名" autocomplete="off" class="layui-input" id="username">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">密 码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="password" lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input" id="password">
                            </div>
                        </div>


                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" type="button" id="login" >登 录</button>
                                <button type="button" class="layui-btn layui-btn-primary" id="register">注 册</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</body>
</html>
